<?php
require_once("../index.php");
 
$db = Zend_Db::factory($config->db);
 
$roles = new Zend_Config_Ini('roles.ini');
 
try {
    echo "\n>>> Delete acl_roles table\n";
    $db->query('DROP TABLE IF EXISTS `acl_roles`');
} catch (Exception $e) {
    echo $e->getMessage();
}
 
try {
    echo "\n>>> Re-creating acl_roles table\n";
    $db->query('CREATE TABLE `acl_roles` (
                `role_id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
                `role_name` VARCHAR(64) NOT NULL UNIQUE);
               ');
 
    foreach ($roles->role as $key=>$value) {
    	try{
        	$db->query('INSERT INTO acl_roles (role_name) VALUES ("' . $value . '")');
        	echo "\n>>> inserted $value \n\n";
    	}catch(Zend_Db_Exception $e){
    		echo $e->getMessage() ;
    	}	
    }
    echo "\n>>> acl_roles table rebuild complete\n\n";
} catch (Exception $e) {
    echo $e->getMessage();
}